#include "shellexecutor.h"

#include <QHBoxLayout>
#include <QDebug>

#include "../settings.h"
#include "../service.h"


ShellExecutor::ShellExecutor(const QString& params, QWidget *parent) :
    QWidget(parent)
{
    QSettings *settings = Settings::getInstance();

    setFont(QFont(settings->value("globals/font_mono").toString(), settings->value("globals/font_mono_size").toInt()));

    QHBoxLayout *mainLayout = new QHBoxLayout(this);

    text = new QTextBrowser(this);

    mainLayout->addWidget(text);

    if(!params.isNull())
        start(params);
}


void ShellExecutor::start(const QString &cmd)
{
    connect(&process, SIGNAL(readyReadStandardOutput()), this, SLOT(readyRead()));
    process.start(cmd);
    process.setReadChannel(QProcess::StandardOutput);
    if (!process.waitForStarted())
        qDebug()<<posInFile<<endl<<"Can't start process "<<cmd;
}

void ShellExecutor::readyRead(){
    QByteArray arr;
    arr = process.readAll();
    text->append(QString(arr));
}
